package com.zjj.provider.service;

import com.zjj.DemoService;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.protocol.rest.support.ContentType;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

/**
 * 参数2 protocol代表用properties声明的 p1和p2这两个protocol ,
 * 当然你也可以用一个,
 */
@Service(version = "rest", protocol = {"p2","p1"})
@Path("demo")  //路径
public class RestDemoService implements DemoService {

    @GET  // get请求
    @Path("say") // 路径
    @Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    @Override
    public String sayHello(@QueryParam("name") String name) {
        System.out.println("执行了rest服务" + name);

        URL url = RpcContext.getContext().getUrl();
        return String.format("%s: %s, Hello, %s", url.getProtocol(), url.getPort(), name);  // 正常访问
    }

}
